<?php

namespace app\common\dao\system\affiche;

use think\db\BaseQuery;
use app\common\dao\BaseDao;
use app\common\model\system\affiche\AfficheCateModel;

class AfficheCateDao extends BaseDao
{
    /**
     * @return AfficheCateModel
     */
    protected function getModel(): string
    {
        return AfficheCateModel::class;
    }

    public function search(array $where, int $propertyId = null)
    {
        return $this->getModel()::getDB()
            ->when($propertyId !== null, function ($query) use ($propertyId) {
                $query->where('property_id', $propertyId);
            })
            ->when(isset($where['is_show']) && $where['is_show'] !== '', function ($query) use ($where) {
                $query->where('is_show', $where['is_show']);
            })
            ->when(isset($where['keywords']) && $where['keywords'] !== '', function ($query) use ($where) {
                $query->whereLike('name|keywords|desc', '%' . trim($where['keywords']) . '%');
            });
    }

}
